//
//  HappyTripIdeasVC.m
//  HappyTrip
//
//  Created by yuxuesong on 15-4-8.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "HappyTripIdeasVC.h"
#import "NewsMainViewController.h"

@interface HappyTripIdeasVC ()

@property (nonatomic, retain)UITextView *textView;
@property (nonatomic, retain)UIAlertView *alertView;

@end

@implementation HappyTripIdeasVC

- (void)dealloc
{
    [_textView release];
    [_alertView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, (VIEW_HEIGHT) / 4 - 50, VIEW_WIDTH - 20 * 2, 30)];
    label.text = @"请输入您的宝贵意见:";
    label.textColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0];
    [self.view addSubview:label];
    [label release];
    
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, (VIEW_HEIGHT - 49) / 4, VIEW_WIDTH - 40, (VIEW_HEIGHT - 49) / 4)];
    //    self.textField.layer.cornerRadius = 5;
    self.textView.layer.borderWidth = 1.0f;
    self.textView.font = [UIFont systemFontOfSize:17];
    self.textView.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0].CGColor;
    [self.view addSubview:self.textView];
    [_textView release];
    
    UIButton *presentButton = [UIButton buttonWithTitle:@"提交" frame:CGRectMake(VIEW_WIDTH * 1 / 5, (VIEW_HEIGHT - 49) / 4 * 2 + 30, VIEW_WIDTH / 5, 30) target:self action:@selector(presentButtonAction:)];
    presentButton.backgroundColor = [UIColor whiteColor];
    [presentButton setTitleColor:[UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    presentButton.layer.borderWidth = 1.0f;
    presentButton.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0].CGColor;
    [self.view addSubview:presentButton];
    
    UIButton *cancelButton = [UIButton buttonWithTitle:@"取消" frame:CGRectMake(VIEW_WIDTH * 3 / 5, (VIEW_HEIGHT - 49) / 4 * 2 + 30, VIEW_WIDTH / 5, 30) target:self action:@selector(cancelButtonAction:)];
    cancelButton.backgroundColor = [UIColor whiteColor];
    [cancelButton setTitleColor:[UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    cancelButton.layer.borderWidth = 1.0f;
    cancelButton.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0].CGColor;
    [self.view addSubview:cancelButton];

}

- (void)presentButtonAction:(UIButton *)button
{
    if (self.textView.text.length < 15) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请您认真填写(不能少于15个字)" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
        [alertView show];
        [alertView release];
    } else {
        self.alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"谢谢您的宝贵意见!" delegate:self cancelButtonTitle:nil otherButtonTitles: nil, nil];
        self.textView.text = nil;
        [self.alertView show];
        [self.alertView release];
        [self.navigationController popViewControllerAnimated:YES];
        [NSTimer scheduledTimerWithTimeInterval:1.2f target:self selector:@selector(dismissAction:) userInfo:nil repeats:NO];
    }
}
- (void)dismissAction:(NSTimer *)timer
{
    [self.alertView dismissWithClickedButtonIndex:0 animated:YES];
}

- (void)cancelButtonAction:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (self.textView.text.length >= 15) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (void)leftBarButtonItemAction:(UIBarButtonItem *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
